package com.app.partner.control;

import com.app.partner.model.User;
import com.app.partner.model.pinglun;
import com.app.partner.service.UserService;
import com.app.partner.service.pinglunService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/pinglunController")
public class pinglunController {
   @Autowired
   pinglunService pinglunService;

    @RequestMapping(value="/partpllistServlet",method= RequestMethod.POST)
    public List<pinglun> findAll() {
        System.out.println("列出pinglun");
        List<pinglun> pinglun = new ArrayList<>();
        try {
            pinglun = pinglunService.findAll();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return pinglun;
    }

    @RequestMapping(value = "/partplServlet",method= RequestMethod.POST)
    public int insert(@Validated @RequestParam(value = "entername",required = false) String entername ,@RequestParam(value = "pinglun",required = false) String pinglun) throws Exception{

        Date time=new Date();
        SimpleDateFormat sdf =   new SimpleDateFormat( " yyyy-MM-dd HH:mm:ss " );
        String nowTime = sdf.format(time);

        pinglunService.save(entername,pinglun,nowTime);
        return 1;
    }

}
